new Vue({
    el: '#app',
    data() {
        return {
            form: {
                Store_SerialNumber: '',
                Store_Name: '',//供应商名称
                Opened_Date: '',//所属地址
                Closed_Date:'',
                Business_License:'',//营业执照
                ProvinceNumber:'',
                CityNumber:'',
                CountyNumber:'',
                Store_Address:'',
                Store_Type:'0',
                Store_SubType:'',
                Enterprise_Info_SerialNumber: '',
            },
            base_system_user_info:[],
            SubType:[{
                label:'天猫店',
                value:'0'
            },{
                label:'抖音店',
                value:'1'
            },{
                label:'美团店',
                value:'2'
            },{
                label:'大众点破',
                value:'3'
            },{
                label:'京东',
                value:'4'
            },{
                label:'小程序',
                value:'5'
            }],
            page: {
                page: 1,
                limit: 10,
            },
            value: [],
            rules: {
                Store_SerialNumber:[{required: true, message: '请输入执照编码', trigger: 'blur' }],
                Store_Name: [{ required: true, message: '请输入店铺名称', trigger: 'blur' }],
                address: [{ required: true, message: '请输入详细地址', trigger: 'blur' }],
            },
            city: [],
            loading: false,
        }
    },
    mounted() {
        const Store_SerialNumber = sessionStorage.getItem("Store_SerialNumber")
        this.getData(Store_SerialNumber);
    },
    watch:{
        'form.Business_License'(Data){
            $.ajax({
                url: BASE_URL1 + "/parseBusinessLicenseAction",
                type: "POST",
                data:{ Data },
                success: function (data) {
                    //parseBusinessLicenseAction
                    console.log(data);
                },
                dataType: "json"
            })
        }
    },
    methods: {
        getData(Store_SerialNumber) {
            const that = this;
            $.ajax({
                url: absolutepath() + "utils/city.json",
                type: "GET",
                success: function (data) {
                    that.city = data
                },
                dataType: "json"
            })
            $.ajax({
                headers:requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/generalQueryByTableNameWithOriginal`,
                type: 'POST',
                data: {
                    Data: "business_store_info",
                    Condition: "Store_SerialNumber='" + Store_SerialNumber + "'"
                },
                success: function (data) {
                    console.log(data);
                    if (data.length == 1) {
                        that.form = data[0];
                        that.value = [that.form.ProvinceNumber, that.form.CityNumber, that.form.CountyNumber];
                    }
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        add_system_user_info(){
            this.base_system_user_info.push({
                User_Number: '',
                ID_Name: '',//表名
                Pass_Word: 'Aa123456',//描述
                Name: '',
                Image: '',
                Sex: '0',//0男1女
                Mail: '',
                Creation_Datetime: '',
                Row_Status: '0',
            })
        },
        remove_system_user_info(){
            if (this.base_system_user_info.length > 0) {
                this.base_system_user_info.pop();
            }else{
                this.$message({
                    message: '不能在删除了',
                    type: 'warning'
                })
            }
        },
        submitForm(formName) {
            // Children: {
            //     base_system_user_role: [{
            //         System_User_Role_SerialNumber: '',
            //         User_Number: '',
            //         Role_SerialNumber: 'store',
            //         Other_SerialNumber: '',
            //     }],
            // }
            const that = this
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    that.loading = true;
                    that.form.ProvinceNumber = that.value[0]; 
                    that.form.CityNumber = that.value[1]; 
                    that.form.CountyNumber = that.value[2];
                    $.ajax({
                        headers: requestHeaders(),
                        url: `${BASE_URL2}/generalBusiness/generalSave`,
                        type: 'POST',
                        data: {
                            Data: JSON.stringify({ Modify: { 
                                business_store_info: [that.form],
                              } 
                            })
                        },
                        success: function (res) {
                            if (res.Status === 'success') {
                                that.$message.success("提交成功")
                                window.history.go(-1);
                            } else {
                                that.$message.error("提交失败，请稍后再试")
                            }
                        },
                        complete: function (XMLHttpRequest) {
                            that.loading = false
                            requestPretreatment(XMLHttpRequest);//config/config.js 响应预检
                        },
                        dataType: "json"
                    })
                } else {
                    that.$message({
                        message: sumberError,
                        type: 'warning'
                    })
                    return false;
                }
            });
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
        },
    }
})